package optimizer;

import java.util.LinkedList;
import simulator.GameChoice;

/**
 * A strategy keeps track of all GameChoices made throughout a game.
 * The index of an item in the LinkedList indicates the game second in which the choice was made.
 * All choices (including WAIT are stored in a strategy)
 */
public class Strategy {
	
	LinkedList<GameChoice> moves;
	int finishTime;

	public Strategy() {
		
		moves = new LinkedList<GameChoice>();
		// set FinishTime to an obviously wrong value
		finishTime = -1;
	}
	
	@SuppressWarnings("unchecked")
	public Strategy(Strategy strategy) {
		
		this.moves = (LinkedList<GameChoice>)strategy.moves.clone();
	}
	
	/**
	 * Adds a choice into the list at the time specified.
	 * @param GameChoice
	 * @param Time
	 */
	public void addMove(GameChoice gameChoice, int time) {
		
		moves.add(time, gameChoice);
	}
	
	/**
	 * Gets the finishTime of a strategy
	 * @return the time the strategy finished at. Or -1 if it was never flagged as finished
	 */
	public int getTime() {
		
		return finishTime;
	}
	
	/**
	 * Prints all moves which are not WAIT
	 * output indicates time.
	 */
	public void printMoves() {
		
		for (int i = 0; i < moves.size(); i++) {
			
			if(moves.get(i).getGameAsset() != null) {
				
				System.out.println("(" + i + ") Move: " + moves.get(i).getGameAsset());
			}
		}
	}
	
	/**
	 * This function sets the finishTime for a strategy
	 * @param time
	 */
	public void setStrategyCompleted(int time) {
		this.finishTime = time;
	}
}
